import { Notification } from 'element-ui';
import main from '/src/main'


const notification = {

    //发起考试成功
    ntfExamSuccess(param) {
        const h = main.$createElement;
        const _text = '提示:';

        Notification({
            title: _text,
            message: h('div', null, [
                '您发起了一场考试：',
                param.examName,
                h('br'),
                '开考时间：',
                param.startTime,
                h('br'),
                '交卷时间：',
                param.endTime,
                h('br'),
                h('br'),
                '点击 ',
                h('a', {
                    attrs: {
                        href: `${window.location.href.split('#')[0]}#/work/examList`
                    },
                    on: {
                        click: () => {
                            window.location.href = `${window.location.href.split('#')[0]}#/work/examList`;
                        }
                    }
                }, '测试列表'),
                ' 查看详情'
            ]),
            duration: 0,
            offset: 60,
            type: "success"
        });

    },

    //正常提示
    ntfCommonSuccess(text,data){
        // 导入vue示例 注册$createElement
        const h = main.$createElement;
        let _text = text;

        if (_text == null || _text == "" || _text == undefined) {
            _text = '提示:'
        }
        Notification({
            title: _text,
            message: h('i', { style: 'color: teal;'}, data),
            duration: 2500,
            offset: 60,
            type:"success"
        });
    },

    //登录后提示
    ntfSuccess(text, data) {
        // 导入vue示例 注册$createElement
        const h = main.$createElement;
        let _text = text;
        let _data = data.data;
        let _identify = "老师";
        // console.info(_data)

        if (_data.role == 2) {
            _identify = "同学"
        }
        if (_data.role == 0) {
            _identify = "管理员"
        }

        if (_text == null || _text == "" || _text == undefined) {
            _text = '操作成功!'
        }
        Notification({
            title: _text,
            message: h('i', { style: 'color: teal;'},   "欢迎您 , " + _data.userName +_identify),
            duration: 2500,
            offset: 60
        });
    },

    //错误提示
    ntfErr(text, message) {
        let _text = text;
        let _message = message;
        Notification({
            title: _text,
            message: _message,
            duration: 0,
            offset: 60,
            type: "warning"
        });
    }
};

export default notification;